package com.uton.rfidcontroller.view.fragment;

import android.content.Intent;

import com.uton.rfidcontroller.R;
import com.uton.rfidcontroller.common.GlobalConstants;
import com.uton.rfidcontroller.databinding.FragmentHasDoWrittenBinding;
import com.uton.rfidcontroller.model.CarDealerListWriteInModel;
import com.uton.rfidcontroller.view.base.BaseRecyclerViewWrittenFragment;
import com.uton.rfidcontroller.viewmodel.fragment_model.HasWrittenViewModel;

import java.util.List;

import io.reactivex.ObservableTransformer;

/**
 * Created by 王家宝 on 2017/10/11.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public class HasWrittenFragment extends
        BaseRecyclerViewWrittenFragment<FragmentHasDoWrittenBinding, HasWrittenViewModel, CarDealerListWriteInModel> {

    @Override
    protected void doOnRefresh() {
        getViewModel().refreshData();
    }

    @Override
    protected void doOnLoadMore() {
    }

    @Override
    public int setLayout() {
        return R.layout.fragment_has_do_written;
    }

    @Override
    public void inject() {
        getBinding().setHasDoWrittenViewModel(getViewModel());
    }

    @Override
    protected HasWrittenViewModel setViewModel() {
        return new HasWrittenViewModel() {
            @Override
            public void doOnRefreshSuccess(List<CarDealerListWriteInModel> tResponse) {
                refreshComplete(tResponse);
                if (isRefreshFirst()) {
                    showData.set(true);
                    showLoading.set(false);
                }
            }

            @Override
            public void doOnRefreshError() {
                stopRefresh();
                if (isRefreshFirst()) {
                    showData.set(true);
                    showLoading.set(false);
                }
            }

            @Override
            public void doOnLoadMoreSuccess(List<CarDealerListWriteInModel> tResponse) {

            }

            @Override
            public void doOnLoadMoreError() {

            }

            @Override
            public ObservableTransformer setObservable() {
                return compose(bindToLifecycle());
            }
        };
    }


    @Override
    public void doSomeThing() {
        super.doSomeThing();
        refreshFirst();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case GlobalConstants.REQUEST_WANT_REFRESH:
                getViewModel().refreshData();
                break;
            default:
                break;
        }
    }
}
